home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / earcd / dev / amos / kyzeramo.lha / Strip.AMOS / Strip.amosSourceCode
AMOS Source Code  |  1992-09-03  |  3KB  |  97 lines

  1. ' compile me!
  2. If Screen=0 : Screen Close 0 : End If : Amos To Back 
  3. FILE$=Command Line$ : STRIP[FILE$] : End 
  4. '
  5. Procedure STRIP[FILE$]
  6.    ' STRIP procedure strips assembler files 
  7.    ' by Kyzer/CSG in July 1995. 
  8.    ' yeah, I _know_ it's really slow, but persevere, eh?
  9.    ' it won't get any faster in AMOS, believe me. 
  10.    '
  11.    If Not Exist(FILE$) Then Pop Proc
  12.    Erase 8 : Erase 9
  13.    Open In 1,FILE$ : L=Lof(1) : Close 1
  14.    Reserve As Work 8,L
  15.    Bload FILE$,Start(8)
  16.    Reserve As Work 9,L
  17.    S=Start(8) : SP=S : SE=S+Length(8)
  18.    D=Start(9) : DP=D
  19.    '
  20.    ' turn all tabs to single spaces for ease. 
  21.    For A=S To SE : If Peek(A)=9 : Poke A,32 : End If : Next 
  22.    Repeat 
  23.       Repeat 
  24.          S$="" : D$=""
  25.          '
  26.          ' get a line 
  27.          Repeat 
  28.             T$=Chr$(Peek(SP)) : S$=S$+T$ : Inc SP
  29.          Until T$=Chr$(10) or SP>=SE
  30.          '
  31.          ' quick check
  32.          A$=Left$(S$,1)
  33.       Until(A$<>"*") and(A$<>";") and(A$<>Chr$(10))
  34.       '
  35.       ' check for errors 
  36.       ERR=False
  37.       N=True
  38.       For A=1 To Len(S$)
  39.          M=Asc(Mid$(S$,A,1))
  40.          If M=34 : N=Instr(S$,Chr$(34),A+1) : Exit If N=0 : A=N : End If 
  41.          If M=39 : N=Instr(S$,Chr$(39),A+1) : Exit If N=0 : A=N : End If 
  42.          Exit If M=59 or M=42
  43.       Next A
  44.       If N=0 Then D$=S$ : Goto WRITEBACK
  45.       '
  46.       ' kill extra spaces  
  47.       S$=S$+Chr$(10)
  48.       For A=1 To Len(S$)
  49.          M=Asc(Mid$(S$,A,1))
  50.          If M=34 : B=Instr(S$,Chr$(34),A+1)
  51.          D$=D$+Mid$(S$,A,B-A) : A=B : End If 
  52.          '
  53.          If M=39 : B=Instr(S$,Chr$(39),A+1)
  54.          D$=D$+Mid$(S$,A,B-A) : A=B : End If 
  55.          '
  56.          Exit If M=59 or M=42
  57.          Exit If M=10
  58.          '
  59.          If M=32 : Repeat : Inc A : M=Asc(Mid$(S$,A,1))
  60.             Until M=10 or M<>32 : Exit If M=10,1
  61.          D$=D$+" " : M=32 : Dec A : End If 
  62.          '
  63.          If M<>32 : OA=A : Repeat : D$=D$+Chr$(M) : Inc A
  64.          M=Asc(Mid$(S$,A,1)) : Until M=32 or M=10 : Dec A : End If 
  65.       Next A
  66.       '
  67.       ' take up the three words alone (label, command, args) 
  68.       D$=D$+" "
  69.       N=1
  70.       For A=1 To 3
  71.          M=Instr(D$," ",N)
  72.          If M Then N=M+1
  73.       Next A
  74.       D$=Left$(D$,N-2)
  75.       '
  76.       ' swap equs for '='s 
  77.       S$=D$ : A=Instr(Lower$(S$)," equ ")
  78.       If A Then D$=Left$(S$,A-1)+"="+Right$(S$,Len(S$)-A-4)
  79.       '
  80.       ' final removal of excess stuff and addition of linefeed 
  81.       D$=D$-Chr$(0) : D$=D$-Chr$(10)
  82.       Repeat : A=(Right$(D$,1)=" ") : If A : D$=Left$(D$,Len(D$)-1)
  83.       End If : Until A=False : D$=D$+Chr$(10)
  84.       '
  85.       ' wahey! one line shortened! 
  86.       WRITEBACK:
  87.       ' if the line below is corrupted, delete it and uncomment the two
  88.       ' below it.
  89.       If D$<>Chr$(10) : Extension_18_015A DP,D$ : DP=DP+Len(D$) : End If 
  90.       ' If D$<>Chr$(10) : For A=0 To Len(D$)-1 : Poke DP+A,Asc(Mid$(D$,A+1,1)
  91.       ' Next A : DP=DP+Len(D$) : End If  
  92.    Until SP>=SE
  93.    '
  94.    ' writeback to disk
  95.    If Exist(FILE$) Then Kill FILE$
  96.    Bsave FILE$,Start(9) To DP
  97. End Proc